# Create a logger object.
import logging
import time
import threading

logger = logging.getLogger('main')
fologger = logging.getLogger('failover')


# more control: https://madmalls.com/blog/post/python-logging-with-color-formatting/

fmt = '%(asctime)s [%(name)s] %(filename)s:%(lineno)d %(levelname)s - %(message)s'
formatter = logging.Formatter(fmt)

# 控制台日志 StreamHandler
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
#fologger.addHandler(stream_handler)

# Initialize coloredlogs.
import coloredlogs
coloredlogs.install(level='INFO')

def failover():
    while True:
        fologger.debug("this is a debugging message")
        fologger.info("this is an informational message")
        fologger.warn("this is a warning message")
        fologger.error("this is an error message")
        fologger.critical("this is a critical message")

        time.sleep(10)

t = threading.Thread(target=failover, args=())
t.start()

logger.debug("this is a debugging message")
logger.info("this is an informational message")
logger.warn("this is a warning message")

logger.critical("this is a critical message")
logger.error("this is an error message")